<?php defined("MAIN_DIR") or die("No direct access");

$banks = array();
$banks_query = "select `bank`.`bank_id`,`bank`.`link`,`bank`.`full_name`,SUM(`vote`.`mark`) as `rating` from `bank`,`vote` where `bank`.`bank_id` = `vote`.`bank_id` and `bank`.`city_id` = '$_SESSION[city]' group by `bank_id` order by `bank_id`";

$limit = 20;
$banks_result = mysql_query($banks_query);
$count = mysql_num_rows($banks_result);
$page = 1;
if (isset($_GET['page']))
	$page = $_GET['page'];
$max_page = ceil($count/$limit);
if ($max_page == 0)
	$max_page++;
if ($page > $max_page)
	$page = $max_page;
elseif ($page < 1)
	$page = 1;
$start_list = (ceil($page)-1)*$limit;
$banks_query .= " limit $start_list,$limit";
$banks_result = mysql_query($banks_query);
$banks_count = mysql_num_rows($banks_result);

$head_title = "Рейтинг банков в ".$current_city['city_name_pred'];
$head_description = "Строится на основании оставленных отзывов о банках ".$current_city['city_name_rod'];
$head_keywords = "рейтинг банков ".mb_strtolower($current_city['city_name'],'utf-8');

require_once APP.HEADFILE;
?>
<script type="text/javascript" src="/files/js/bank_list.js"></script>
<h1>Рейтинг банков</h1>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td align="left" valign="top" class="banki_main_col">
			<div class="banki_search_block">
				В рейтинге участвуют лишь те банки, о работе которых были оставлены пользовательские отзывы
				<div class="reiting_prim">Рейтинг общероссийский</div>
			</div>
			<div id="banki_table"><?php
				if ($banks_count > 0)
				{
					$i = 0;
					?><table width="100%" border="0" cellspacing="0" cellpadding="0"><?php
					while ($banks_row = mysql_fetch_array($banks_result))
					{
						$i++;
						?><tr>
							<td width="34" align="center" valign="middle" class="banki_table_item banki_table_number"><?php
								echo $i+($page-1)*$limit;
							?></td>
							<td width="536" align="left" valign="middle"  class="banki_table_item">
								<a href="<?php echo "/$c_name";?>/banks/<?php echo $banks_row['link'].".html"; ?>"><?php echo $banks_row['full_name'];?></a>
							</td>
							<td width="174" align="left" valign="middle" class="banki_table_item"><?php
								if ($i == 1 && $page == 1)
									echo "<strong>$banks_row[rating]</strong><div class='reiting_ball'>".word_ending($banks_row['rating'],"балл","балла","баллов",false)."</div>";
								else
									echo $banks_row['rating'];
							?></td>
						</tr><?php
					}
					?></table><?php
				}
				else
					echo "<h3 class='gag'>Банки не найдены</h3>";
			?></div>
			<div id="oprosy_table">
				<?php require_once APP."pageskin.php"; ?>
			</div>
		</td>
		<td width="218" align="left" valign="top">
			<div id="reiting_page_gol"><strong><a href="<?php echo "/$c_name";?>/mentions/voting/">Проголосовать за банк!</a></strong></div><?php
			require_once APP."vacancy_column.php";
		?></td>
	</tr>
</table>
<div class="inside_block">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr valign='top'>
			<td width="344" class="inside_info"><?php
				require_once APP."bank_list.php";
				require_once APP."currency_rates.php";
			?></td>
			<td width="646"><?php
				$info = mysql_fetch_array(mysql_query("select * from `info` where `info_id` = '6' limit 1"));
				$text = getRichText($info['text']);
				echo "<h2>$info[header]</h2>";
				echo "<p>$text</p>";
			?></td>
		</tr>
	</table>
</div>
<?php require_once APP.FOOTERFILE; ?>